/*
 * @Description:  任务
 * @Author: Myruun
 * @Date: 2021-04-19 16:03:57
 * @LastEditors: Myruun
 * @LastEditTime: 2021-08-26 17:34:42
 * @FilePath: \serve\controller\log.js
 */
const mysqlQuery = require("../unit/mysql.js");

// 获取任务列表
exports.Index = async (ctx, next) => {
  let body = ctx.request.body;
  const id = body.id || "";
  let sql = "";
  if (id) {
    sql =
      "SELECT * FROM log  WHERE  id ='" +
      id +
      "' order by id desc";
  } else {
    sql = "SELECT * FROM log  WHERE  order by id desc";
  }
  let obj = await mysqlQuery(sql);
  ctx.response.body = obj;
};

// 添加log
exports.add = async (content, state, parame, url) => {
  const time = Math.round(new Date() / 1000);
  let sql = `INSERT INTO log (content, state, parame, url, creation_time, id) VALUES ('${content}','${state}','${parame}','${url}','${time}',0)`;
  let obj = await mysqlQuery(sql);
};
